<template>
    <div>
        <h2>等级添加</h2>
        <table class="table table-primary">
            <tbody>
                <tr>
                    <td>等级名称</td>
                    <td>
                        <input type="text" v-model="quertinfo.LevelName">
                    </td>
                </tr>

                <tr>
                    <td></td>
                    <td>
                        <input type="button" value="添加" class="btn btn-primary" @click="add">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import {ref,reactive} from 'vue'
import {useRouter} from 'vue-router'
const router=useRouter();
import axios from 'axios';

let quertinfo=reactive({
    LevelName:''
})

const add=()=>{
    //验证有效性
    if(quertinfo.LevelName==""){
        alert('等级名称不能为空');
        return;
    }
    //发送网络请求
    axios({
        method:'post',
        url:'/api/Member/AddLevel',
        data:quertinfo
    })
    .then(res=>{
        console.log(res);
        if(res.data==-1){
            alert('等级名称重复');
            return;
        }
        if(res.data>0){
            alert('成功');
            router.push('/getlevel')
        }
        else{
            alert('失败');
        }
    })
    .catch(err=>{
        console.error(err);
    })
}

</script>

<style scoped>

</style>